package indzcraft.calc;

import java.util.HashMap;

public class ProcDB {
	
	HashMap<String,Proc> procDB = new HashMap<String,Proc>();
	
	public ProcDB(){
		populate();
	}
	
	public void populate(){
		
		procDB.put("key_to_the_endless_chamber", new Proc(15,75,0.1,"agi",1710));
		
		procDB.put("left_eye_of_rajh", new Proc(10,50,0.1,"agi",1710)); // TODO only crit
		
		procDB.put("prestors_talisman_of_machination", new Proc(15,75,0.1,"haste",1926));
		
		procDB.put("arrow_of_time", new Proc(20,50,0.2,"haste",1149));
		
		procDB.put("the_hungerer", new Proc(15,60,1,"haste",1532));
		procDB.put("the_hungerer_heroic", new Proc(15,60,1,"haste",1730));
		
		procDB.put("matrix_restabilizer", new Proc(30,105,0.1,"haste",1624));
		procDB.put("matrix_restabilizer_heroic", new Proc(30,105,0.1,"haste",1834));
		
		procDB.put("starcatcher_compass", new Proc(20,115,0.15,"haste",2904));
		procDB.put("starcatcher_compass_heroic", new Proc(20,115,0.15,"haste",3278));
		procDB.put("starcatcher_compass_lfr", new Proc(20,115,0.15,"haste",2573));
		
		procDB.put("badge_of_conquest_403", new Proc(20,120,1,"agi",2419));
		
		procDB.put("wrath_of_unchaining", new Proc(10,0,1,"agi",88,10));
		procDB.put("wrath_of_unchaining_lfr", new Proc(10,0,1,"agi",78,10));
		procDB.put("wrath_of_unchaining_heroic", new Proc(10,0,1,"agi",99,10));
	}
	
	public Proc get(String name){
		return procDB.get(name);
	}
	public boolean has(String name) {
		if(procDB.containsKey(name))
			return true;
		return false;
		
	}
	
	class Proc {
		int icd = 0;
		int duration = 0;
		double proc_chance = 0;
		int value = 0;
		String stat = ""; // e.g. haste
		int maxstacks = 0;
		public Proc(int duration, int icd, double proc_chance,
				String stat, int value) {
			this.duration = duration;
			this.icd = icd;
			this.proc_chance = proc_chance;
			this.stat = stat;
			this.value = value;
		}
		public Proc(int duration, int icd, double proc_chance,
				String stat, int value, int maxstacks) {
			this.duration = duration;
			this.icd = icd;
			this.proc_chance = proc_chance;
			this.stat = stat;
			this.value = value;
			this.maxstacks = maxstacks;
		}
		
		public double boost(double total_hits) {
			double boost = 0.;
			try {
				if(proc_chance == 1){
					if(maxstacks == 0){
						double d = (double) duration;
						boost = d/icd*value;
					}
					else{
						boost = value*maxstacks;
					}
				}
				else if(icd == 0 || duration == 0 || proc_chance == 0 || value == 0)
					throw new Exception("Proc not valid");
				else
					boost = duration/(icd+1/(total_hits*proc_chance))*value;
			} catch (Exception e) {
				e.printStackTrace();
			}
			return boost;
		}
	}
}
